import sys

def fib(num: int):
    if num < 1:
        return 0
    if num < 3:
        return 1
    return fib(num - 1) + fib(num - 2)


def get_fibnum(margin: int, index=0):
    nums = []
    if margin <= 0:
        nums.append(0)
        print('end')

    for i in range(0, margin + 1):
        result = fib(i)
        if result <= margin:
            if 0 < index < len(nums):
                return nums
            else:
                nums.append(result)
        else:
            print('end')
            break
    return nums


def get_fibnum_by_index(index: int, margin: int):
    if index <= 0:
        return 0
    nums = get_fibnum(margin, index)
    if len(nums) <= index:
        print('out of index')
        return []
    return nums[index - 1]


# 取100以内的数列
print(get_fibnum(100))

# 取指定下标数
print(get_fibnum_by_index(10, 10000))
